﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace TheVerge.Phone.Converters
{
    /// <summary>
    /// We are trying to convert the HTML Browser Font-Size percentage to a value
    /// that mimics it's actual size for a text UI control on the phone.
    /// </summary>
    public class FontSizePercantageToWinPhoneConverter : IValueConverter
    {
        private const double RATIO = 0.15625;

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                var d = (double)value;
                return d * RATIO;
            }
            catch { return value; }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                var d = (double)value;
                return d / RATIO;
            }
            catch { return value; }
        }
    }
}
